Skip to content
This repository has been archived by the owner on Sep 11, 2023. It is now read-only.

Commit

Permalink
Close files in fingerprint test
Browse files Browse the repository at this point in the history
  • Loading branch information
djaglowski committed May 21, 2021
1 parent e85de66 commit 42931ad
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions operator/builtin/input/file/fingerprint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ func TestFingerprintStartsWith_FromFile(t *testing.T) {

fullFile, err := ioutil.TempFile(tempDir, "")
require.NoError(t, err)
defer fullFile.Close()

_, err = fullFile.Write(content)
require.NoError(t, err)

Expand All @@ -253,24 +255,23 @@ func TestFingerprintStartsWith_FromFile(t *testing.T) {

partialFile, err := ioutil.TempFile(tempDir, "")
require.NoError(t, err)
defer partialFile.Close()

// Write the first byte before comparing, since empty files will never match
_, err = partialFile.Write(content[:1])
require.NoError(t, err)
content = content[1:]

// Write one byte at a time and validate that updated
// full fingerprint still starts with partial
// Write one byte at a time and validate that
// full fingerprint still starts with updated partial
for i := range content {
_, err = partialFile.Write(content[i:i])
require.NoError(t, err)

pff, err := operator.NewFingerprint(partialFile)
require.NoError(t, err)

match := fff.StartsWith(pff)

require.True(t, match)
require.True(t, fff.StartsWith(pff))
}
}

Expand Down

0 comments on commit 42931ad

Please sign in to comment.